package com.xrkj.b2c.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.xrkj.b2c.controller.common.BasicController;
import com.xrkj.b2c.model.sys.SysMenu;
import com.xrkj.b2c.service.sys.SysMenuService;

/**
 * 主页控制器类 
 * @author 赵子靖
 *
 */
@RequestMapping("/index")
@Controller
public class XrkjIndexController extends BasicController{
    @Autowired
    private SysMenuService menuService;
	private Logger logger=Logger.getLogger(XrkjIndexController.class);
	/**
	 * 转向系统主页方法
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/index")
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response){
		
		//获取菜单
		Map<String, Object> paramter = new HashMap<String, Object>();
        paramter.put("mParentId", "root");
        paramter.put("mStatus", SysMenu.STATUS_1);
        List<SysMenu> menus = menuService.findMenuList(paramter);
        if(menus!=null && menus.size()>0){
            for (SysMenu menu : menus) {
                Map<String, Object> subParamter = new HashMap<String, Object>();
                subParamter.put("mParentId", menu.getmId());
                subParamter.put("mStatus", SysMenu.STATUS_1);
                menu.setSubSysMenus(menuService.findMenuList(subParamter)); 
            }
        }
        request.setAttribute("menus", menus);
		return new ModelAndView("WEB-INF/index");
	}
	/**
	 * 转向系统首页方法
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/systemindex")
	public ModelAndView systemindex(HttpServletRequest request,HttpServletResponse response){
		return new ModelAndView("WEB-INF/pages/sys/systemindex");
	}
}
